/**
 *  *2010-5-15 下午01:09:50  add 
 */
package com.base.myproject.client.HR.bcode;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.swfupload.client.SWFUpload;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.LasyObejct;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.DataSet;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.ui.BaseFileUploadDialog;
import com.base.myproject.client.ui.BaseFormPanel;
import com.base.myproject.client.ui.BaseGrid;
import com.base.myproject.client.ui.BaseGridPanel;
import com.base.myproject.client.ui.SignleFileUpload;
import com.base.myproject.client.ui.celleditor.BaseComboBoxForm;
import com.base.myproject.client.ui.celleditor.BaseComboBoxX;
import com.base.myproject.client.ui.dialog.ShowImageDialog;
import com.extjs.gxt.ui.client.GXT;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.GridEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.MessageBoxEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.ListView;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.TabItem;
import com.extjs.gxt.ui.client.widget.TabPanel;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Label;

/**
 * @author Administrator
 */ 
public class Bcode_HR extends LayoutContainer implements LasyObejct {
	BaseStore<BusiObject> mainstore = null;
	SignleFileUpload swfu; // 显示上传界面
	
	Button addimage = new Button("添加图片");
	Button delimage = new Button("删除图片");
	
	BaseComboBoxForm<BaseModelData> C_num32 ;//个税策略
	TextField<String> C_num2;//人员编码
	
	ArrayList<BaseStore> refresh_list = new ArrayList<BaseStore>() ;
	
	BaseComboBoxX bc16;
	BaseComboBoxX C_num17;
	BaseComboBoxX C_num18;
	public Bcode_HR(BaseStore<BusiObject> mainstore) {
		this.mainstore = mainstore;
		init();
		addimage.addListener(Events.Select, getListener());
		delimage.addListener(Events.Select, getListener());
		//this.setStyleAttribute("background-color", "#DFE8F6");
	}
	public Bcode_HR() {
	}


	void init() {
		initwidget();

	}

	private void initwidget() {
		FieldSet fs1 = new FieldSet();
		fs1.add(createForm());
		fs1.setBorders(false);
		TabPanel tabpanel = new TabPanel();
		tabpanel.setPlain(true);
		tabpanel.setHeight(225);
		tabpanel.setWidth(740);
		TabItem t1 = new TabItem();
		t1.setText("联络方式");
		t1.add(createGrid());
		t1.setScrollMode(Scroll.AUTO);
		
		TabItem t2 = new TabItem();
		t2.setText("身份证件");
		t2.add(create_card_Grid());
		t2.setScrollMode(Scroll.AUTO);
		tabpanel.add(t2);
		tabpanel.add(t1);
		
		
		VerticalPanel v = new VerticalPanel();
		v.setSpacing(5);
		v.add(fs1);
		v.add(tabpanel);
		this.add(v);
	}
	TextField<String> C_num3 = new TextField<String>();
	TextField<String> C_num4 = new TextField<String>();
	TextField<String> C_num28 = new TextField<String>();
	TextField<String> age = new TextField<String>();
	DateField C_data15;//出生日期
	BaseComboBoxX C_numsex;//性别
	BaseComboBoxX C_numcx = new BaseComboBoxX("name","dictionary", "where type='hr_cz'");
	BaseFormPanel form;
	BaseFormPanel createForm() {
		form = new BaseFormPanel(mainstore);
		form.setBodyBorder(false);
		form.setStyleName("form_css2");
		form.setPadding(6);
		TableLayout tl = new TableLayout(8);

		TableData td = new TableData();
		td.setRowspan(1);
		td.setHorizontalAlign(HorizontalAlignment.LEFT);
		td.setVerticalAlign(VerticalAlignment.MIDDLE);
		td.setPadding(2);
		
		TableData td2 = new TableData();
		
		td2.setRowspan(7);
		td2.setHorizontalAlign(HorizontalAlignment.RIGHT);
		td2.setVerticalAlign(VerticalAlignment.TOP);
		td2.setPadding(2);
		td2.setColspan(2);
		
		form.setLayout(tl);
		form.setHeaderVisible(false);

		form.add(new Label("人员编码:"), td);
		C_num2 = new TextField<String>();
		C_num2.setWidth(127);
		C_num2.setEnabled(false);
		C_num2.setFireChangeEventOnSetValue(true);
		C_num2.setName("bcode");
		C_num2.addListener(Events.Change, getListener());
		form.add(C_num2, td);
		
		form.add(new Label("姓:"), td);	
		C_num3.setName("hr_firstname_zh");
		C_num3.setWidth(127);
		C_num3.setAllowBlank(false);
		C_num3.setEmptyText("这个是必填字段");
		C_num3.addListener(Events.Change, getListener());
		form.add(C_num3, td);

		form.add(new Label("名:"), td);
		C_num4.setName("hr_lastname_zh");
		C_num4.setWidth(127);
		C_num4.setAllowBlank(false);
		C_num4.setEmptyText("这个是必填字段");
		C_num4.addListener(Events.Change, getListener());
		form.add(C_num4, td);
		
		//图片显示
		form.add(CreateView(), td2);
		
		form.add(new Label("简码:"), td);
		TextField<String> C_num24 = new TextField<String>();
		C_num24.setWidth(127);
		C_num24.setName("shortcode");
		form.add(C_num24, td);
		
		form.add(new Label("姓名:"), td);
		C_num28.setEnabled(false);
		C_num28.setWidth(127);
		C_num28.setFireChangeEventOnSetValue(true);
		C_num28.setName("bname");
		form.add(C_num28, td);

		form.add(new Label("性别:"), td);
		C_numsex = new BaseComboBoxX("name","dictionary", "where type='hr_sex'");
		C_numsex.setWidth(127);
		C_numsex.setName("sex");
		form.add(C_numsex, td);
		
		form.add(new Label("firstname:"), td);
		TextField<String> C_num5 = new TextField<String>();
		C_num5.setWidth(127);
		C_num5.setName("hr_firstname_en");
		form.add(C_num5, td);
		
		form.add(new Label("lastname:"), td);
		TextField<String> C_num6 = new TextField<String>();
		C_num6.setWidth(127);
		C_num6.setName("hr_lastname_en");
		form.add(C_num6, td);
		
		form.add(new Label("别名:"), td);
		TextField<String> C_num8 = new TextField<String>();
		C_num8.setWidth(127);
		C_num8.setName("hr_name_Alias");
		form.add(C_num8, td);
		
		form.add(new Label("年龄:"), td);
		age.setWidth(127);
		age.setFireChangeEventOnSetValue(true);
		age.setEnabled(false);
		age.setName("age");
		form.add(age, td);

		form.add(new Label("出生日期:"), td);
		C_data15 = new DateField();
		C_data15.setFireChangeEventOnSetValue(true);
		C_data15.setEnabled(false);
		C_data15.setWidth(127);
		C_data15.getPropertyEditor().setFormat(
				DateTimeFormat.getFormat("yyyy-M-d"));
		C_data15.setName("bird");
		form.add(C_data15, td);
		
		form.add(new Label("国籍:"), td);
		TextField<String> C_num13 = new TextField<String>();
		C_num13.setWidth(127);
		C_num13.setName("hr_nationality");
		form.add(C_num13, td);
		
		form.add(new Label("户籍省份:"), td);
		
		bc16 = new BaseComboBoxX("name","dictionary","where type='hr_p'");//new BaseComboBoxX("name","dictionary", "where type='hr_a'");//new BaseComboBoxForm<BaseModelData>("code","name","dictionary","where type='hr_a'",true);
		bc16.setWidth(127);
		bc16.setName("hr_Census_Province");
		form.add(bc16, td);
		
		form.add(new Label("户籍市:"), td);
		C_num17 =new BaseComboBoxX("name","dictionary","where type='hr_c'");// new BaseComboBoxForm<BaseModelData>("code","name","dictionary","where type='hr_a'",true);
		C_num17.setWidth(127);
		C_num17.setName("hr_Census_city");
		form.add(C_num17, td);
		
		form.add(new Label("户籍区:"), td);
		C_num18 = new BaseComboBoxX("name","dictionary","where type='hr_a'");//new BaseComboBoxX("name","dictionary", "where type='hr_a'");//
		C_num18.setWidth(127);
		C_num18.setName("hr_Census_area");
		form.add(C_num18, td);
		
		form.add(new Label("城/乡:"), td);
		C_numcx.setWidth(127);
		C_numcx.setAllowBlank(false);
		C_numcx.setEmptyText("这个是必填字段");
		C_numcx.setName("hr_City_Township");
		form.add(C_numcx, td);
		
		form.add(new Label("婚姻状况:"), td);
		BaseComboBoxX C_num14 = new BaseComboBoxX("name","dictionary", "where type='hr_marry'");
		C_num14.setWidth(127);
		C_num14.setName("hr_Marital_status");
		form.add(C_num14, td);
		
		form.inited();

		return form;
	};
	
	int sync = 0;
	Listener<BaseEvent> defaultlistener;

	Listener<BaseEvent> getListener() {
		if (defaultlistener != null) {
			return defaultlistener;
		}
 
		defaultlistener = new Listener<BaseEvent>() {
			public void handleEvent(BaseEvent be) {
				sync++;
				try {
					if (sync == 1) {
						if (be.getType() == Events.Select) {
							if (be.getSource().equals(addimage)) {
								swfu = new SignleFileUpload("*.jpg", 1, 50);
								swfu.setUrl("gwtbase/uploadFileServlet?table=bcode_images&file=bcodeimage&action=insert&bcode=" + mainstore.getValue("bcode"));
								swfu.setParent(getImageStore());
								swfu.setValue(mainstore);
								swfu.showDialog();
							}
							else if (be.getSource().equals(delimage)) {
								if(view.getSelectionModel().getSelectedItems().size()>0)
								{
									 MessageBox.confirm("确认", "确定要删除这个雇员的图片吗?", new Listener<MessageBoxEvent>()
											 {
												@Override
												public void handleEvent(MessageBoxEvent be) {
													
													if(be.getButtonClicked().getText().equals(
															GXT.MESSAGES.messageBox_yes()))
													{
														for(BusiObject bo:view.getSelectionModel().getSelectedItems())
														{	
															getImageStore().remove(bo);
														}
														getImageStore().trySave();
														view.refresh();
													}
												}
											 });  
								}
								else
								{
									MessageBox.info("提示", "你还没选中图片", null);
								}
							}
						} else if (be.getType() == Events.Change) {
	
						if(be.getSource().equals(C_num3) || be.getSource().equals(C_num4)){
								C_num28.setFireChangeEventOnSetValue(true);
								C_num3.setValue(C_num3.getRawValue().trim());
								C_num4.setValue(C_num4.getRawValue().trim());
								C_num28.setValue(C_num3.getRawValue().trim()+C_num4.getRawValue().trim());
							}
						} 
						else if (be.getType() == Events.DoubleClick) {
							if (be.getSource().equals(view)) {
								ShowImageDialog.getInstance().show("", view.getSelectionModel().getSelectedItem().get("bcodeimagepath")+"");
							}
						} 
						else if (be.getType() == Events.KeyUp) {
							if (be instanceof ComponentEvent) {
								if (((ComponentEvent) be).getKeyCode() == 13) // 回车
								{
								}
							}
						}else if(be.getType() == Events.AfterEdit){
							final GridEvent<BusiObject> ge = (GridEvent)be;
							if( ge.getProperty().equals("addr")){
								String sqlPos = "select mark from dictionary where type='hr_hotelsection'";
								final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT.create(com.base.myproject.client.tools.GreetingService.class);
								   greetingService2.getDataSet(sqlPos, new AsyncCallback<DataSet>(){
									@Override
									public void onFailure(Throwable caught) {	
									}
									@Override
									 public void onSuccess(DataSet result) {	
										String value = ge.getValue().toString();
										C_num18.setFireChangeEventOnSetValue(true);
										C_num17.setFireChangeEventOnSetValue(true);
										bc16.setFireChangeEventOnSetValue(true);
										//现在只能用这种方法，如果从一开始就设置好上面的事件的话，只要一改地址，不改证件号
										//或只改证件号不改地址的话都会把没改的动态设置的COMBOBOX设置成空，以至于保存不了
										if(result.getRowCount()>0){	
											String province = result.getValue(0, "mark");
											String city = result.getValue(1, "mark");
											String town = result.getValue(2, "mark");
											if(value.indexOf(town) == -1){
												BusiObject bo = new BusiObject();
												bo.set("code", "区外");
												bo.set("value", "区外");
												C_num18.setValue(bo);
											}else{
												BusiObject bo = new BusiObject();
												bo.set("code", "区内");
												bo.set("value", "区内");
												C_num18.setValue(bo);
												
												BusiObject bo2 = new BusiObject();
												bo2.set("code", "市内");
												bo2.set("value", "市内");
												C_num17.setValue(bo2);	
											}
											if(value.indexOf(city)== -1){
												BusiObject bo2 = new BusiObject();
												bo2.set("value", "市外");
												bo2.set("code", "市外");
												C_num17.setValue(bo2);
											}else{
												BusiObject bo2 = new BusiObject();
												bo2.set("value", "市内");
												bo2.set("code", "市内");
												C_num17.setValue(bo2);		
												
												BusiObject bo1 = new BusiObject();
												bo1.set("value", "省内");
												bo1.set("code", "省内");
												bc16.setValue(bo1);
											}
											if(value.indexOf(province) == -1){
												BusiObject bo1 = new BusiObject();
												bo1.set("value", "省外");
												bo1.set("code", "省外");
												bc16.setValue(bo1);
											}else{
												BusiObject bo1 = new BusiObject();
												bo1.set("value", "省内");
												bo1.set("code", "省内");
												bc16.setValue(bo1);
											}
										}
										C_num18.setFireChangeEventOnSetValue(false);
										C_num17.setFireChangeEventOnSetValue(false);
										bc16.setFireChangeEventOnSetValue(false);
									  }
								     });   
							}else if(ge.getProperty().equals("idNo")){
								int index= ge.getRowIndex();
								String type="";
								if(cardgridpanel.getBg().getValue(index, "type")==null){
									cardgridpanel.getBg().setValue(index, "idNo", "");
									MessageBox.info("提示", "填写证件号码前必须先选择证件类型!", null);
									return;
								}else{
									C_numsex.setFireChangeEventOnSetValue(true);
									type=cardgridpanel.getBg().getValue(index, "type").toString();
									if(type.endsWith("身份证")){
										if(cardgridpanel.getBg().getValue(index, "idNo")!=null){
											String idno=cardgridpanel.getBg().getValue(index, "idNo").toString();
											BusiObject bo = new BusiObject();
											if(idno.length()==15){//15位身份证
												String bird_year =idno.substring(6, 8);//出生年
												String bird_month =idno.substring(8, 10);//出生月
												String bird_day =idno.substring(10, 12);//出生日
												String sex =idno.substring(14, 15);//性别
												String bird="19"+bird_year+"-"+bird_month+"-"+bird_day;
												int s=Integer.parseInt(sex);
												if(s%2==0){
													sex="女";
												}else{
													sex="男";
												}
												C_data15.setValue(change_to_date(bird));
												age.setValue(String.valueOf(new Date().getYear() + 1900 - Integer.parseInt("19"+bird_year)));
												bo.set("value", sex);
												bo.set("code", sex);
												C_numsex.setValue(bo);
											}else if(idno.length()==18){//18位身份证
												String bird_year =idno.substring(6, 10);//出生年
												String bird_month =idno.substring(10, 12);//出生月
												String bird_day =idno.substring(12, 14);//出生日
												String sex =idno.substring(16, 17);//性别
												String bird=bird_year+"-"+bird_month+"-"+bird_day;
												int s=Integer.parseInt(sex);
												if(s%2==0){
													sex="女";
												}else{
													sex="男";
												}
												C_data15.setValue(change_to_date(bird));
												age.setValue(String.valueOf(new Date().getYear() + 1900 - Integer.parseInt(bird_year)));
												bo.set("code", sex);
												bo.set("value", sex);
												C_numsex.setValue(bo);
												
											}else{
												cardgridpanel.getBg().setValue(index, "idNo", "");
												MessageBox.info("提示", "您输入的身份证号码有误,(身份证号码为:15位或18位有效字符)!", null);
												return;
											}
										}
									}
									
									C_numsex.setFireChangeEventOnSetValue(false);
								}
							}
						}
					}
				} finally {
					sync--;
				}
			}

		};
		return defaultlistener;
	}

	BaseStore<BusiObject> addrstore = null;
	BaseStore<BusiObject> getStore() {
		if (addrstore == null) {
			createStore();
		}
		return addrstore;
	}
	BaseStore<BusiObject> createStore() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("bcode");
		type.getField("bcode").setType(String.class);
		type.addField("addrtype");
		type.getField("addrtype").setType(String.class);
		type.addField("addr");
		type.getField("addr").setType(String.class);
		StoreInfo info = new StoreInfo();
		info.setTablename("bcodeaddr");
		info.setKeyname(new String[] { "icode" });
		info
				.setSql("select icode,bcode,addrtype,addr from bcodeaddr where bcode='{bcode}'");
		info.setParent(mainstore);// 关联主表
		info.setLinkparentcolumns(new String[] { "bcode" }); // 关联主表字段
		info.setLinkparent_chile_columns(new String[] { "bcode" });// 关联主表字段
		addrstore = new BaseStore<BusiObject>(type, info);
		return addrstore;
	}

	BaseGridPanel gridpanel = null;
	BaseGridPanel createGrid() {
		CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());
		BaseComboBoxX bc3 = new BaseComboBoxX("name","dictionary", "where type='hr_addrtype'");
		
		ColumnConfig C3 = new ColumnConfig("addrtype", "类型", 100);
		C3.setEditor(bc3.getCellEditor());
		columns.add(C3);
		ColumnConfig C4 = new ColumnConfig("addr", "内容", 200);
		columns.add(C4);
		C4.setEditor(new CellEditor(new TextField<String>()));

		ColumnModel cm = new ColumnModel(columns);
		gridpanel = new BaseGridPanel(getStore(), cm,true,true);
		cbs.setSelectionMode(SelectionMode.SINGLE);
		gridpanel.getBg().setSelectionModel(cbs);
		gridpanel.getBg().setBorders(false);
		gridpanel.getBg().setHeight(175);
		return gridpanel;
	}
	/**********/
	BaseStore<BusiObject> idcardstore = null;
	BaseStore<BusiObject> get_idcard_Store() {
		if (idcardstore == null) {
			create_idcard_Store();
		}
		return idcardstore;
	}
	BaseStore<BusiObject> create_idcard_Store() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("bcode");
		type.getField("bcode").setType(String.class);
		type.addField("type");
		type.getField("type").setType(String.class);
		type.addField("idNo");
		type.getField("idNo").setType(String.class);
		type.addField("addr");
		type.getField("addr").setType(String.class);
		type.addField("availableDate");
		type.getField("availableDate").setType(Date.class);
		type.addField("passAvailableDate");
		type.getField("passAvailableDate").setType(Date.class);
		type.addField("issue");
		type.getField("issue").setType(String.class);
		
		StoreInfo info = new StoreInfo();
		info.setTablename("hr_idCard");
		info.setKeyname(new String[] { "icode" });
		info
				.setSql("select * from hr_idCard where bcode='{bcode}'");
		info.setParent(mainstore);// 关联主表
		info.setLinkparentcolumns(new String[] { "bcode" }); // 关联主表字段
		info.setLinkparent_chile_columns(new String[] { "bcode" });// 关联主表字段
		idcardstore = new BaseStore<BusiObject>(type, info);
		return idcardstore;
	}
	BaseGridPanel cardgridpanel = null;
	BaseGridPanel create_card_Grid() {
		CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());
		
		BaseComboBoxX bc1 = new BaseComboBoxX("name","dictionary", "where type='hr_cardtype'");
		ColumnConfig C1 = new ColumnConfig("type", "证件类型", 80);
		C1.setEditor(bc1.getCellEditor());
		columns.add(C1);

		ColumnConfig C2 = new ColumnConfig("idNo", "证件号", 140);
		columns.add(C2);
		C2.setEditor(new CellEditor(new TextField<String>()));
		
		ColumnConfig C3 = new ColumnConfig("addr", "地址", 200);
		columns.add(C3);
		C3.setEditor(new CellEditor(new TextField<String>()));
		
		ColumnConfig C4 = new ColumnConfig("availableDate", "有效日期", 85);
		DateField dateField4 = new DateField();  
	    dateField4.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));  
	    C4.setEditor(new CellEditor(dateField4));
	    C4.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		columns.add(C4);
		
		ColumnConfig C5 = new ColumnConfig("passAvailableDate", "签证有效期", 85);
		DateField dateField5 = new DateField();  
	    dateField5.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));  
	    C5.setEditor(new CellEditor(dateField5));
	    C5.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		columns.add(C5);
		
		ColumnConfig C6 = new ColumnConfig("issue", "签发机关", 110);
		columns.add(C6);
		C6.setEditor(new CellEditor(new TextField<String>()));
		

		ColumnModel cm = new ColumnModel(columns);
		cardgridpanel = new BaseGridPanel(get_idcard_Store(), cm,true,true);
		cbs.setSelectionMode(SelectionMode.SINGLE);
		cardgridpanel.getBg().setSelectionModel(cbs);
		cardgridpanel.getBg().setHeight(175);
		cardgridpanel.getBg().setBorders(false);
		BaseGrid grid = cardgridpanel.getBg();
		grid.addListener(Events.AfterEdit, getListener());
		return cardgridpanel;
	}
	
/*******/
	BaseStore<BusiObject> imagestore = null;
	BaseStore<BusiObject> getImageStore(){
	if(imagestore==null) 
	{
		createImageStore();
	}
	return imagestore;}
	BaseStore<BusiObject> createImageStore(){
	ModelType type = new ModelType();
	type.setRoot("records");
	type.setRecordName("record");
	type.setTotalName("totle");
	type.addField("icode");
	type.getField("icode").setType(Long.class);
	type.addField("bcode");
	type.getField("bcode").setType(String.class);
	type.addField("bcodeimagepath");
	type.getField("bcodeimagepath").setType(String.class);
	StoreInfo info = new StoreInfo();
	info.setTablename("bcode_images");
	info.setKeyname(new String[] { "icode"});
	info.setSql("select * from bcode_images where bcode='{bcode}'");
	info.setParent(mainstore);// 关联主表
	info.setLinkparentcolumns(new String[] { "bcode" }); // 关联主表字段
	info.setLinkparent_chile_columns(new String[] { "bcode" });// 关联主表字段
	imagestore = new BaseStore<BusiObject>(type, info);
	 return imagestore;}
	
	
	public void addReFreshStore(BaseStore bs)
	{
		refresh_list.add(bs);
	}
	/*
	 * 人员图片
	 */
	ListView<BusiObject> view=null;
	
	ContentPanel CreateView() {
		final ContentPanel panel = new ContentPanel();
		//panel.setCollapsible(true);
		//panel.setAnimCollapse(false);
		panel.setFrame(true);
		panel.setId("images-view");
		panel.setHeaderVisible(false);
		panel.setWidth(147);//159
		panel.setStyleName("bcode_img_view");
		panel.setBodyBorder(false);
		// panel.setAutoHeight(true);
		panel.setHeight(180);
		
		
		ToolBar tb= new ToolBar();
		tb.add(addimage);
		tb.add(delimage);
		

		view = new ListView<BusiObject>() {
			@Override
			protected BusiObject prepareData(BusiObject model) {
				return model;
			}

		};

		view.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);  
		view.setTemplate(getTemplate());
		view.setStore(getImageStore());
		view.setHeight(140);//119
		view.setItemSelector("div.thumb-wrap");
		view.getSelectionModel().addListener(Events.SelectionChange,
				new Listener<SelectionChangedEvent<BusiObject>>() {

					public void handleEvent(SelectionChangedEvent<BusiObject> be) {
						panel
								.setHeading("产品图片("
										+ be.getSelection().size()
										+ " 个产品被选中)");
					
					}

				});

		//view.addListener(Events.DoubleClick, getListener());
		panel.add(view);
		panel.setTopComponent(tb);
		return panel;
	}
	private native String getTemplate() /*-{

	
	return ['<tpl  for=".">', 
    '<div class="thumb-wrap" id="{name}" style="border: 1px solid white;text-align:center;">', 
    '<div class="thumb" style="text-align:center;" ><img style="width:90px;height:120px;border:5px double #eee;margin: 3px 2px 2px 3px" src="{bcodeimagepath}" title="{name}"></div>', 
    '</div>', 
    '</tpl>',
    '<div class="x-clear"></div>'].join(""); 
}-*/;
	@Override
	public boolean isopen() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean open() {
		// TODO Auto-generated method stub
		return false;
	}
	/**********
	 * 传入一个日期字符串 2010-09-09 返回一个日期对象
	 * ***********/
	Date change_to_date(String strdate){//2010-09-15
		java.util.Date currentTime = new java.util.Date();
		Date df_date=new Date();
		int year=Integer.parseInt(strdate.substring(0, 4))-1900;
		int month=Integer.parseInt(strdate.substring(5, 7))-1;
		int day=Integer.parseInt(strdate.substring(8, 10));
		df_date.setYear(year);
		df_date.setMonth(month);
		df_date.setDate(day);
		return df_date;
	}	
	

}
